<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
    require([ "dojo/_base/array", "dojo/_base/xhr", "dojo/request", "dojo/topic", "dojo/json", "dojo/_base/lang",
            "dijit/Dialog" ], function(array, xhr, request, topic, JSON, lang, Dialog) {
        var deletItemsCount = 0;
        var refreshTree = "phonegroup/refreshZtree";
        var issharednow = 1;
        phonebookRestForm = function(formId) {
            dijit.byId(formId).reset();
            document.getElementById("PhonebookBirthdayNS").value = "";
            document.getElementById("PhonebookBirthdayUpdateNS").value = "";
            if (formId.indexOf('UFD') != -1) {
                var rowid = jQuery("#phonebookNSGird").jqGrid('getGridParam', 'selrow');
                var phonebook = jQuery("#phonebookNSGird").jqGrid('getRowData', rowid);
                dijit.byId('phonebookNSUFD').setValues(phonebook);
            }
        };
        topic.subscribe("phonebook/insertOrUpdate", phonebookRestForm);
        var syncDB = function(url, jsonData) {
            request.post(url, {
                data : jsonData,
                headers : {
                    'Content-Type' : "application/json; charset=utf-8"
                },
                timeout : 30000
            }).then(function(response) {
                topic.publish("notifyMsgTopic", {
                    message : '操作成功!' || response,
                    type : "message",
                    duration : 1000
                });
                topic.publish(refreshTree);
                var currentPage = jQuery('#phonebookNSGird').jqGrid('getGridParam', 'page');
                var pageSize = jQuery('#phonebookNSGird').jqGrid('getGridParam', 'rowNum');
                var totalCount = jQuery('#phonebookNSGird').jqGrid('getGridParam', 'records') - deletItemsCount;
                var totalPages = Math.ceil(totalCount / pageSize);
                jQuery("#phonebookNSGird").jqGrid('setGridParam', {
                    page : currentPage > totalPages ? totalPages : currentPage
                }).trigger("reloadGrid");
            }, function(error) {
                alert(error);
            });
        };
        phonebookSubmitForm = function(formId, type) {
            var url = "phonebook/insert";
            if (type == 'u') {
                url = "phonebook/update";
            }
            var form = dijit.byId(formId);
            if (form.isValid()) {
                var formData = form.getValues();
                lang.mixin(formData, {
                    userid : userid
                });
                var json = JSON.stringify(formData);
                syncDB(url, json);
                form.hide();
                /*  if (dijit.byId()){}; */
                topic.publish("phonebook/insertOrUpdate", formId);
            } else {
                form.validate();
            }
        };
        phonebookDelete = function() {
            var ids = jQuery("#phonebookNSGird").jqGrid('getGridParam', 'selarrrow') || [];
            deletItemsCount = ids.length;
            if (ids.length > 0) {
                if (confirm('确认删除所选定的项？')) {
                    var phonebook = {};
                    phonebook.id = '';
                    array.forEach(ids, function(entry, i) {
                        phonebook.id += entry + ",";
                    });
                    syncDB("phonebook/delete", JSON.stringify(phonebook));
                }
            } else {
                alert('请选择至少一条数据!');
            }
        };
        phonebookQuery = function(formId) {
            var phonebook = dijit.byId(formId).getValues();
            jQuery("#phonebookNSGird").jqGrid('setGridParam', {
                postData : phonebook,
                mtype : "post"
            }).trigger('reloadGrid');
        };
        /* phonegroupRestForm = function(formId) {
            dijit.byId(formId).reset();
            if (formId.indexOf('UFD') != -1) {
                var rowid = jQuery("#phonegroupGird").jqGrid('getGridParam', 'selrow');
                var phonegroup = jQuery("#phonegroupGird").jqGrid('getRowData', rowid);
                dijit.byId('phonegroupUFD').setValues(phonegroup);
            }
        };
        topic.subscribe("phonegroup/insertOrUpdate", phonegroupRestForm);
         */
        phonegroupSubmitForm = function(formId, type) {
            var url = "phonegroup/insert";
            if (type == 'u') {
                url = "phonegroup/update";
            }
            var form = dijit.byId(formId);
            if (form.isValid()) {
                var formData = form.getValues();
                lang.mixin(formData, {
                    userid : userid
                });
                var json = JSON.stringify(form.getValues());
                syncDB(url, json);
                form.hide();
                topic.publish("phonegroup/insertOrUpdate", formId);
            } else {
                form.validate();
            }
        };
        
        phonegroupDelete = function() {
            var ids = jQuery("#phonegroupGird").jqGrid('getGridParam', 'selarrrow') || [];
            deletItemsCount = ids.length;
            if (ids.length > 0) {
                if (confirm('确认删除所选定的项？')) {
                    var phonegroup = {};
                    phonegroup.id = '';
                    array.forEach(ids, function(entry, i) {
                        phonegroup.id += entry + ",";
                    });
                    jQuery("#phonebookNSGird").jqGrid('setGridParam', {
                        postData : {
                            groupid : treeNode.groupid
                        },
                        mtype : "post"
                    }).trigger('reloadGrid');
                    syncDB("phonegroup/delete", JSON.stringify(phonegroup));
                }
            } else {
                alert('请选择至少一条数据!');
            }
        };
        phonegroupQuery = function(formId) {
            var phonegroup = dijit.byId(formId).getValues();
            jQuery("#phonegroupGird").jqGrid('setGridParam', {
                postData : phonegroup,
                mtype : "post"
            }).trigger('reloadGrid');
        };
        
        // zTree 
        var addHoverDom = function(treeId, treeNode) {
            var sObj = jQuery("#" + treeNode.tId + "_span");
            if (treeNode.editNameFlag || jQuery("#addBtn_" + treeNode.id).length > 0)
                return;
            var addStr = "<span class='button add' id='addBtn_" + treeNode.id
                    + "' title='新增节点' onfocus='this.blur();'></span>";
            sObj.after(addStr);
            var btn = jQuery("#addBtn_" + treeNode.id);
            if (btn) {
                btn.bind("click", function() {
                    var zTree = jQuery.fn.zTree.getZTreeObj(treeId);
                    if (!treeNode.open) {
                        zTree.expandNode(treeNode);
                    }
                    var phonegroupNSIFD = dijit.byId('phonegroupNSIFD');
                    phonegroupNSIFD.setValues({
                        pid : treeNode.menuid
                    });
                    phonegroupNSIFD.show();
                    var handle = topic.subscribe(refreshTree, function() {
                        zTree.reAsyncChildNodes(null, "refresh");
                        handle.remove();
                    });
                    return false;
                });
            }
        };
        var removeHoverDom = function(treeId, treeNode) {
            jQuery("#addBtn_" + treeNode.id).unbind().remove();
        };
        var showRemoveBtn = function(treeId, treeNode) {
            return (treeNode.level != 0);
        };
        var showRenameBtn = function(treeId, treeNode) {
            return (treeNode.level != 0);
        };
        var beforeRename = function(treeId, treeNode, newName) {
            var zTree = jQuery.fn.zTree.getZTreeObj(treeId);
            
            if (newName.length == 0) {
                alert("节点名称不能为空.");
                setTimeout(function() {
                    zTree.editName(treeNode);
                }, 10);
                return false;
            }
            
            var phonegroup = {};
            phonegroup.groupid = treeNode.groupid;
            phonegroup.groupname = newName;
            phonegroup.isshared = treeNode.isshared;
            phonegroup.sn = treeNode.sn;
            phonegroup.userid = treeNode.userid;
            phonegroup.ispublic = treeNode.ispublic;
            
            syncDB("phonegroup/update", JSON.stringify(phonegroup));
            var handle = topic.subscribe(refreshTree, function() {
                zTree.reAsyncChildNodes(null, "refresh");
                handle.remove();
            });
            return true;
        };
        var beforeRemove = function(treeId, treeNode) {
            var zTree = jQuery.fn.zTree.getZTreeObj(treeId);
            zTree.selectNode(treeNode);
            var isDel = confirm("确认删除  '" + treeNode.groupname + "' 吗？");
            if (isDel) {
                var phonegroup = {};
                phonegroup.id = treeNode.groupid;
                syncDB("phonegroup/delete", JSON.stringify(phonegroup));
                var handle = topic.subscribe(refreshTree, function() {
                    zTree.reAsyncChildNodes(null, "refresh");
                    handle.remove();
                });
            } else {
                return false;
            }
        };
        var beforeDrag = function(treeId, treeNodes) {
            return false;
        };
        var zTreeOnClick = function(event, treeId, treeNode) {
            jQuery("#phonebookNSGird").jqGrid('setGridParam', {
                postData : {
                    groupid : treeNode.groupid,
                    isshared : 0,
                    userid : userid
                },
                mtype : "post"
            }).trigger('reloadGrid');
        };
        var setting = {
            async : {
                enable : true,
                url : "phonegroup/queryGroupLevel?isshared=0&userid="+userid
            },
            check : {
                enable : false,
                chkboxType : {
                    "Y" : "s",
                    "N" : "p"
                }
            },
            view : {
                addHoverDom : addHoverDom,
                removeHoverDom : removeHoverDom,
                selectedMulti : false
            },
            edit : {
                enable : true,
                editNameSelectAll : true,
                showRemoveBtn : showRemoveBtn,
                showRenameBtn : showRenameBtn
            },
            data : {
                key : {
                    name : 'groupname'
                },
                simpleData : {
                    enable : false,
                    idKey : 'groupid'
                }
            },
            callback : {
                beforeDrag : beforeDrag,
                beforeRename : beforeRename,
                beforeRemove : beforeRemove,
                onClick : zTreeOnClick
            }
        };
        jQuery.fn.zTree.init(jQuery("#phoneGroupNSTree"), setting);
    });
</script>
<div data-dojo-type="dijit/Dialog" id="phonegroupNSIFD" title="新增">
  <div class="dijitDialogPaneContentArea">
    <table>
      <tr>
        <td><label for="groupname">分组名称: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text" name="groupname"></td>
      </tr>
      <tr style="display: none;">
        <td><label for="isshared">是否共享：</label></td>
        <td><select data-dojo-type="dijit/form/Select" name="isshared" data-dojo-props="required: true, trim:true" style="width: 182px;">
            <option value="0">私有</option>
        </select></td>
      </tr>
    </table>
  </div>
  <div class="dijitDialogPaneActionBar">
    <button data-dojo-type="dijit/form/Button" type="button" onclick="phonegroupSubmitForm('phonegroupNSIFD','i')">保存</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="phonegroupRestForm('phonegroupNSIFD');">重置</button>
  </div>
</div>
<div data-dojo-type="dijit/Dialog" id="phonegroupNSUFD" title="更新">
  <div class="dijitDialogPaneContentArea">
    <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, readOnly: true" type="text" name="groupid" style="display: none;">
    <table>
      <tr>
        <td><label for="groupname">分组名称: </label></td>
        <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text" name="groupname"></td>
      </tr>
      <tr style="display: none;">
        <td><label for="isshared">是否共享：1=共享、0=私有: </label></td>
        <td><select data-dojo-type="dijit/form/Select" name="isshared" data-dojo-props="required: true" style="width: 182px;">
            <option value="0">私有</option>
        </select></td>
      </tr>
    </table>
  </div>
  <div class="dijitDialogPaneActionBar">
    <button data-dojo-type="dijit/form/Button" type="button" onclick="phonegroupSubmitForm('phonegroupUFD','u')">保存</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="phonegroupRestForm('phonegroupUFD');">重置</button>
  </div>
</div>
<div>
  <div style="width: 18%; height: 555px; float: left;" data-dojo-type="dijit/layout/AccordionContainer">
    <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="selected:true,title:'通讯录'">
      <div>
        <ul id="phoneGroupNSTree" class="ztree" style="margin: 0px; padding: 0; border: 0 solid white; background: white; overflow-y: hidden;"></ul>
      </div>
    </div>
  </div>
  <div style="width: 80%; float: right;">
    <div data-dojo-type="dijit/Dialog" style="width: 550px;" id="phonebookNSIFD" title="新增">
      <div class="dijitDialogPaneContentArea">
        <table>
          <tr>
            <td><label for="fullname">姓名: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text" name="fullname"></td>
            <td><label for="title">性别： </label></td>
            <td><select data-dojo-type="dijit/form/Select" name="title" data-dojo-props="trim:true" style="width: 182px;">
                <option value="1">男</option>
                <option value="0">女</option>
            </select></td>
          </tr>
          <tr>
            <td><label for="nickname">昵称: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, trim:true" type="text" name="nickname"></td>
            <td><label for="birthday">出生日期: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" style="width: 180px;" data-dojo-props="trim:true" type="text" id="PhonebookBirthdayNS" name="birthday" class="Wdate"
              onClick="WdatePicker()"></td>
          </tr>
          <tr>
            <td><label for="duty">职务: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true" type="text" name="duty"></td>
            <td><label for="spouse">配偶: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true" type="text" name="spouse"></td>
          </tr>
          <tr>
            <td><label for="childs">子女: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true" type="text" name="childs"></td>
            <td><label for="companyname">单位名称: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true" type="text" name="companyname"></td>
          </tr>
          <tr>
            <td><label for="companyaddress">单位地址: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true" type="text" name="companyaddress"></td>
            <td><label for="companyphone">单位电话: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="companyphone"></td>
          </tr>
          <tr>
            <td><label for="companyfax">单位传真: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="companyfax"></td>
            <td><label for="homeaddress">家庭住址: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true" type="text" name="homeaddress"></td>
          </tr>
          <tr>
            <td><label for="homezip">家庭邮编: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="homezip"></td>
            <td><label for="mobile">移动电话: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="mobile"></td>
          </tr>
          <tr>
            <td><label for="phone">固定电话: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="phone"></td>
            <td><label for="email">邮箱: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="regExp: '^\\w*?@\\w*?\.(com|net|cn|org|com\.cn)$', invalidMessage:'请输入正确邮箱地址'" type="text" name="email"></td>
          </tr>
          <tr>
            <td><label for="qq">QQ号码: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="qq"></td>
            <td><label for="msn">MSN: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true,regExp: '^\\w*?@\\w*?\.(com|net|cn|org|com\.cn)$', invalidMessage:'请输入正确邮箱地址'" type="text"
              name="msn"></td>
          </tr>
          <tr>
            <td><label for="groupid">联系人分组: </label></td>
            <td><div id="groupidNSSelectINS"></div></td>
            <td  style="display: none;"><select data-dojo-type="dijit/form/Select" name="isshared" data-dojo-props="required: true, trim:true" style="width: 182px;">
                <option value="0">私有</option>
            </select></td>
          </tr>
          <tr> 
            <td><label for="note">备注: </label></td>
            <td><input data-dojo-type="dijit/form/SimpleTextarea" data-dojo-props="trim:true" type="text" name="note"></td>
          </tr>
        </table>
      </div>
      <div class="dijitDialogPaneActionBar">
        <button data-dojo-type="dijit/form/Button" type="button" onclick="phonebookSubmitForm('phonebookNSIFD','i')">保存</button>
        <button data-dojo-type="dijit/form/Button" type="button" onclick="phonebookRestForm('phonebookNSIFD');">重置</button>
      </div>
    </div>
    <div data-dojo-type="dijit/Dialog" style="width: 550px;" id="phonebookNSUFD" title="更新">
      <div class="dijitDialogPaneContentArea">
        <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, readOnly: true" type="text" name="phoneid" style="display: none;">
        <table>
          <tr>
            <td><label for="fullname">姓名: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text" name="fullname"></td>
            <td><label for="title">性别： </label></td>
            <td><select data-dojo-type="dijit/form/Select" name="title" style="width: 182px;">
                <option value="1">男</option>
                <option value="0">女</option>
            </select></td>
          </tr>
          <tr>
            <td><label for="birthday">出生日期: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" style="width: 180px;" type="text" id="PhonebookBirthdayUpdateNS" name="birthday" class="Wdate" onClick="WdatePicker()"></td>
            <td><label for="nickname">昵称: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true" type="text" name="nickname"></td>
          </tr>
          <tr>
            <td><label for="duty">职务: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" type="text" name="duty"></td>
            <td><label for="spouse">配偶: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" type="text" name="spouse"></td>
          </tr>
          <tr>
            <td><label for="childs">子女: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" type="text" name="childs"></td>
            <td><label for="companyname">单位名称: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" type="text" name="companyname"></td>
          </tr>
          <tr>
            <td><label for="companyaddress">单位地址: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" type="text" name="companyaddress"></td>
            <td><label for="companyphone">单位电话: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="companyphone"></td>
          </tr>
          <tr>
            <td><label for="companyfax">单位传真: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="companyfax"></td>
            <td><label for="homeaddress">家庭住址: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" type="text" name="homeaddress"></td>
          </tr>
          <tr>
            <td><label for="homezip">家庭邮编: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="homezip"></td>
            <td><label for="mobile">移动电话: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim: true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="mobile"></td>
          </tr>
          <tr>
            <td><label for="phone">固定电话: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="phone"></td>
            <td><label for="email">邮箱: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="regExp: '^\\w*?@\\w*?\.(com|net|cn|org|com\.cn)$', invalidMessage:'请输入正确邮箱地址'" type="text" name="email"></td>
          </tr>
          <tr>
            <td><label for="qq">QQ号码: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="trim:true,regExp: '^(-?\\d+)$', invalidMessage:'请输入正确的数字'" type="text" name="qq"></td>
            <td><label for="msn">MSN: </label></td>
            <td><input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="regExp: '^\\w*?@\\w*?\.(com|net|cn|org|com\.cn)$', invalidMessage:'请输入正确邮箱地址'" type="text" name="msn"></td>
          </tr>

          <tr>
            <td><label for="groupid">联系人分组: </label></td>
            <td><div id="groupidNSSelectUPS"></div></td>
            <td  style="display: none;"><select data-dojo-type="dijit/form/Select" name="isshared" data-dojo-props="required: true" style="width: 182px;">
                <option value="0">私有</option>
            </select></td>
          </tr> 
          <tr>
            <td><label for="note">备注: </label></td>
            <td><input data-dojo-type="dijit/form/SimpleTextarea" type="text" name="note"></td>
          </tr>
          </tr>
        </table>
      </div>
      <div class="dijitDialogPaneActionBar">
        <button data-dojo-type="dijit/form/Button" type="button" onclick="phonebookSubmitForm('phonebookNSUFD','u')">保存</button>
        <button data-dojo-type="dijit/form/Button" type="button" onclick="phonebookRestForm('phonebookNSUFD');">重置</button>
      </div>
    </div>
    <fieldset>
      <legend>&nbsp;&nbsp;信息选项&nbsp;&nbsp;</legend>
      <form id="queryPhonebookNSForm" data-dojo-type="dijit/form/Form" method="post">
        <div style="margin-left: 5px;">
          <table>
            <tr>
              <td><label for="fullname">姓名: </label></td>
              <td width="200"><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="fullname"></td>
              <td><label for="nickname">昵称: </label></td>
              <td width="200"><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="nickname"></td>
            </tr>
          </table>
        </div>
      </form>
      <div style="padding: 5px;">
        <button id="phonebookNSInsertBtn" data-dojo-type="dijit/form/Button" type="submit" label="新增">
          <script type="dojo/method" event="onClick" args="evt">
        require([ "dijit/form/Select","dojo/json","dojo/request", "dojo/_base/lang"], 
           function(Select,JSON,request,lang) {
             request.post("phonegroup/select", {
               headers : {
                 'Content-Type' : "application/json; charset=utf-8"
               },
               timeout : 30000
             }).then(function(response) {
               var ops=JSON.parse(response);
               dijit.byId("groupidNSSelectINS").options=[]; 
               lang.mixin(ops[0], {selected: true});
               dijit.byId("groupidNSSelectINS").addOption(ops);
             }, function(error) {
               alert(error);
             });
        });
        dijit.byId('phonebookNSIFD').show();
      </script>
        </button>
        <button id="phonebookNSDeleteBtn" data-dojo-type="dijit/form/Button" type="button" label="删除" onclick="phonebookDelete();"></button>
        <button id="phonebookNSUpdateBtn" data-dojo-type="dijit/form/Button" type="button" label="更新">
          <script type="dojo/method" event="onClick" args="evt">
        var ids = jQuery("#phonebookNSGird").jqGrid('getGridParam', 'selarrrow') || [];
        if (ids.length != 1) {
          alert('每次只能修改一条数据!');
        }else{
          require([ "dijit/form/Select","dojo/json","dojo/request"], 
            function(Select,JSON,request) {
              request.post("phonegroup/select", {
                headers : {
                  'Content-Type' : "application/json; charset=utf-8"
                },
                timeout : 30000
              }).then(function(response) {
                var ops=JSON.parse(response);
                dijit.byId("groupidNSSelectUPS").options=[]; 
                dijit.byId("groupidNSSelectUPS").addOption(ops);
                var phonebook = jQuery("#phonebookNSGird").jqGrid('getRowData', ids[0]);
                dijit.byId('phonebookNSUFD').setValues(phonebook);
                dijit.byId('phonebookNSUFD').show();
              }, function(error) {
            alert(error);
          });
        });
          
        };
      </script>
        </button>
        <button id="phonebookNSQueryBtn" data-dojo-type="dijit/form/Button" type="button" label="查询" onclick="phonebookQuery('queryPhonebookNSForm');"></button>
      </div>
    </fieldset>
    <div id="girdNS">
      <table id="phonebookNSGird"></table>
      <div id="phonebookNSToolbar"></div>
    </div>
  </div>
</div>

<script type="text/javascript">
    require([ "dijit/form/Select", "dojo/json", "dojo/request" ], function(Select, JSON, request) {
        request.post("phonegroup/select", {
            headers : {
                'Content-Type' : "application/json; charset=utf-8"
            },
            timeout : 30000
        }).then(function(response) {
            var ops = JSON.parse(response);
            new Select({
                name : "groupid",
                style : "width: 80%",
                options : ops
            }, "groupidNSSelectINS").startup();
            new Select({
                name : "groupid",
                style : "width: 80%",
                options : ops
            
            }, "groupidNSSelectUPS").startup();
            
        }, function(error) {
            alert(error);
        });
    });
</script>

<script type="text/javascript">
    jQuery("#phonebookNSGird").jqGrid(
            {
                url : 'phonebook/queryAsList',
                datatype : "json",
                autowidth : true,
                rownumbers : true,
                height : 380,
                colNames : [ '通讯簿ID', '姓名', '先生、女士、小姐', '出生日期', '昵称', '职务', '配偶', '子女', '单位名称', '单位地址', '单位电话', '单位传真',
                        '家庭住址', '家庭邮编', '移动电话', '固定电话', '邮箱', 'QQ号码', 'MSN', '备注', '用户ID', '联系人分组', '是否共享：1=共享、0=私有' ],
                colModel : [ {
                    name : 'phoneid',
                    index : 'phoneid',
                    width : 60,
                    key : true,
                    hidden : true,
                    align : 'center'
                }, {
                    name : 'fullname',
                    index : 'fullname',
                    width : 60,
                    align : 'center'
                }, {
                    name : 'title',
                    index : 'title',
                    hidden : true
                }, {
                    name : 'birthday',
                    index : 'birthday',
                    hidden : true
                }, {
                    name : 'nickname',
                    index : 'nickname',
                    hidden : true
                }, {
                    name : 'duty',
                    index : 'duty',
                    hidden : true
                }, {
                    name : 'spouse',
                    index : 'spouse',
                    hidden : true
                }, {
                    name : 'childs',
                    index : 'childs',
                    hidden : true
                }, {
                    name : 'companyname',
                    index : 'companyname',
                    hidden : true
                }, {
                    name : 'companyaddress',
                    index : 'companyaddress',
                    hidden : true
                }, {
                    name : 'companyphone',
                    index : 'companyphone',
                    hidden : true
                }, {
                    name : 'companyfax',
                    index : 'companyfax',
                    hidden : true
                }, {
                    name : 'homeaddress',
                    index : 'homeaddress',
                    hidden : true
                }, {
                    name : 'homezip',
                    index : 'homezip',
                    hidden : true
                }, {
                    name : 'mobile',
                    index : 'mobile',
                    width : 90,
                    align : 'center'
                }, {
                    name : 'phone',
                    index : 'phone',
                    width : 90,
                    align : 'center'
                }, {
                    name : 'email',
                    index : 'email',
                    width : 150,
                    align : 'center'
                }, {
                    name : 'qq',
                    index : 'qq',
                    width : 90,
                    align : 'center'
                }, {
                    name : 'msn',
                    index : 'msn',
                    width : 150,
                    align : 'center'
                }, {
                    name : 'note',
                    index : 'note',
                    hidden : true
                }, {
                    name : 'userid',
                    index : 'userid',
                    hidden : true
                }, {
                    name : 'groupid',
                    index : 'groupid',
                    hidden : true
                }, {
                    name : 'isshared',
                    index : 'isshared',
                    hidden : true
                } ],
                rowNum : 15,
                rowList : [ 15, 20, 25, 30 ],
                pager : '#phonebookNSToolbar',
                recordpos : 'right',
                viewrecords : true,
                sortorder : "desc",
                jsonReader : {
                    repeatitems : false
                },
                multiselect : true,
                shrinkToFit : false,
                caption : "通讯簿列表"
            });
    jQuery("#phonebookNSGird").jqGrid('navGrid', '#phonebookNSToolbar', {
        edit : false,
        add : false,
        del : false,
        search : false,
        refresh : true
    });
</script>
